package com.easyadmin.modules.stock.service.impl;

import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.modules.stock.domain.SysInvestModelEntity;
import com.easyadmin.modules.stock.domain.SysInvestRulesEntity;
import com.easyadmin.modules.stock.mapper.SysInvestModelDao;
import com.easyadmin.modules.stock.mapper.SysInvestRulesDao;
import com.easyadmin.modules.stock.service.SysInvestRulesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;


@Service("sysInvestRulesService")
public class SysInvestRulesServiceImpl extends ServiceImpl<SysInvestRulesDao, SysInvestRulesEntity> implements SysInvestRulesService {

    @Autowired
    SysInvestRulesDao sysInvestRulesDao;

    @Override
    public PageInfo<SysInvestRulesEntity> queryPage(SysInvestRulesEntity sysInvestRulesEntity, PageDomain pageDomain) {
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<SysInvestRulesEntity> data =sysInvestRulesDao.selectList(new QueryWrapper<SysInvestRulesEntity>().lambda()
                .eq(StringUtils.isNotBlank(sysInvestRulesEntity.getStcrCode()),
                        SysInvestRulesEntity::getStcrCode,sysInvestRulesEntity.getStcrCode())
                .like(StringUtils.isNotBlank(sysInvestRulesEntity.getStcrName()),
                        SysInvestRulesEntity::getStcrName,sysInvestRulesEntity.getStcrName()));
        return new PageInfo<>(data);
    }

    @Override
    public boolean update(SysInvestRulesEntity sysInvestRulesEntity) {
        Integer result = sysInvestRulesDao.updateById(sysInvestRulesEntity);
        return result > 0;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchRemove(String[] ids) {
        for(String  id:ids){
            sysInvestRulesDao.deleteById(id);
        }
        return true;
    }

}